package xzy.Filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebFilter(filterName = "Login_Filter")
public class Login_Filter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {

        HttpServletRequest httpRequest = (HttpServletRequest) req;
        HttpServletResponse response=(HttpServletResponse)resp;
        List<String> list_url=new ArrayList<String>();
        list_url.add("/Student-info.jsp");
        list_url.add("/Student-info2.jsp");
        list_url.add("/index2.jsp");
        list_url.add("/index3.jsp");
        list_url.add("/main.jsp");
        list_url.add("/studentResist");
        String url_input=httpRequest.getRequestURI();
        if(list_url.contains(url_input)){
            response.sendRedirect("/");
        }else {
            chain.doFilter(req, resp);
        }

        }

    public void init(FilterConfig config) throws ServletException {

    }

}
